﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using QLST_DTO;

namespace QLST_DAO
{
    public class HOADONDAO : TempDAO
    {
        /// <summary>
        /// Thêm hóa đơn
        /// </summary>
        /// <param name="HD"></param>
        /// <returns>MaHoaDon: Them thành công, -1: Thêm thất bại</returns>
        public int Insert(HOA_DON HD)
        {
            SqlParameter[] parameters = new SqlParameter[6];
            parameters[0] = new SqlParameter("@NgayLap", HD.NgayLap);
            parameters[1] = new SqlParameter("@MaNVThuNgan", HD.MaNVThuNgan);
            parameters[2] = new SqlParameter("@MaKH", HD.MaKH);
            parameters[3] = new SqlParameter("@TongSoLuong", HD.TongSoLuong);
            parameters[4] = new SqlParameter("@TongTien", HD.TongTien);
            parameters[5] =
                    new SqlParameter("@SoHoaDon", SqlDbType.Int);
            parameters[5].Direction = ParameterDirection.Output;
            int flag = dap.ExcuteProcedureWithReturn("st_InsertHoaDon", parameters);
            if (flag > 0)
            {
                return (int)parameters[5].Value;
            }
            return flag;
        }
    }
}
